// import axios from "axios"
export default {
  name: "Register",
  data() {
    return {
      urseName: "",
      password: "",
      userCode: "",
      time: 0,

      // 正则输入 不正确
      usernameError: false,
      passwordError: false,

      // 正则输入正确

      zhengze: {
        username: false,
        password: false,

      }
    };


  },

  methods: {
    /** 
    * 注册表单正则表达式验证
    */
    //手机号正则(11位数字)
    usernameTest() {
      let urseName = /^1[0-9]{10}$/
      if (urseName.test(this.urseName)) {
        this.zhengze.username = true
        this.usernameError = false
      } else {
        this.usernameError = true
      }
    },

    //密码不能含有非法字符，长度在4-10之间gb                                                                                                
    passwordTest() {
      let password = /^[a-zA-Z0-9]{4,10}$/
      if (password.test(this.password)) {
        this.zhengze.password = true
        this.passwordError = false
      } else {
        this.passwordError = true
      }
    },




    to_sign_in() {
      this.$emit('Login_status', true, false, false)
    },
    // 手机验证请求
    Verification() {
      if (this.zhengze.username == true) {
        this.$axios({
          method: "GET",
          url: "/api/send",
          params: {
            phone: this.urseName,
          },
        })
          // 成功
          .then((res) => {
            alert(res.data.msg)

            // 设置验证码时间为60秒
            this.time = 60
            let timer = setInterval(() => {
              console.log(1);
              if (this.time > 0) {
                this.time--
                console.log(this.time);
              } else if (this.time == 0) {
                clearInterval(timer)
              }
            }, 1000)
          })
          // 失败
          .catch((err) => {
            console.error(err);
          });
      }else{
        alert('请输入正确的电话号码！')
      }
    },
    // 手机注册
    registerFuns() {
      // if(
      //   this.zhengze.username &&
      //   this.zhengze.password 
      // ){
      this.$axios({
        method: "POST",
        url: "/api/register",
        params: {
          userCellphone: this.urseName,
          userPassword: this.password,
          userCode: this.userCode,
        },
      })
        // 成功
        .then((res) => {
          console.log(res.data);
          if (res.data.code == '3004') {
            alert(res.data.msg);
          } else {
            alert(res.data.msg);
            (this.urseName = ""), (this.password = ""), (this.userCode);
            this.$emit('SignInShow')
          }
        })
        // 失败
        .catch((err) => {
          console.error(err);
        });
      // }
    },

  },
};
